package huawei;
/*
* @Author: wanghongfucoder
* @Date:   2017-06-27 16:12:56
* @Last Modified by:   wanghongfucoder
* @Last Modified time: 2017-06-27 16:19:13
*/

public class SubSumLinear {
	public static void main(String[] args) {
		int[] arr={-10,1,2,3, 4, -5, -23, 3, 7, -21};
		int max=maxSubSumLinear(arr);
		System.out.println(max);
	}

	public static int  maxSubSumLinear(int[] arr){
		
		int max=0;
		int thismax=0;
		for (int i=0; i<arr.length; i++) {
			thismax+=arr[i];
			if (thismax<0) {
				thismax=0;
			}
			if (max<thismax) {
				max=thismax;
			}
		}
		return max;
	}
}